#include<stdio.h>
#include<sqlite3.h> 
#include<string.h>
#include <stdlib.h>
typedef int(*Sqlite_cb)(void *para,int columnCount,char **columnValue,char**columnName);
int main(int argc,char **argv)
{
    int id;
    int age;

    char name[20];

    char sql[1024]={0};
    char*errmsg;

    if(argc!=2)
    {
        printf("please input db name\n");
        return 1;
    }
    sqlite3 * db;
    int ret=sqlite3_open(argv[1],&db);

    if(ret!=SQLITE_OK)
    {
        printf("sqlite3_open error%s",sqlite3_errmsg(db));
        return 1;
    }
    printf("sqlite open db successful!\n");
    strcpy(sql,"create table IF NOT EXISTS student(id integer primary key,name text,age integer);");
    ret= sqlite3_exec(db,sql,nullptr,nullptr,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("exec error:%s\n",sqlite3_errmsg(db));
    }
  
    for(int i=0;i<3;i++)
    {
        memset(sql,0,strlen(sql));
        printf("please input id:\n");
        scanf("%d",&id);

        printf("please input name:\n");
        scanf("%s",name);

        printf("please input age:\n");
        scanf("%d",&age);

        sprintf(sql,"insert into student(id,name,age) values(%d,'%s',%d)",id,name,age);
        ret= sqlite3_exec(db,sql,nullptr,nullptr,&errmsg);
        if(ret!=SQLITE_OK)
        {
            printf("exec error:%s\n",sqlite3_errmsg(db));
            exit(1);
        }
    }
    memset(sql,0,strlen(sql));
    memset(name,0,strlen(name));
    scanf("%s",name);
    sprintf(sql,"delete from student where name='%s';",name);
    ret= sqlite3_exec(db,sql,nullptr,nullptr,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("exec error:%s\n",sqlite3_errmsg(db));
        exit(1);
    }
    sqlite3_close(db);
    return 0;
}